package com.example.hello.client.Navbar;

import com.example.hello.BootstrapNavbar;
import com.github.gwtbootstrap.client.ui.constants.NavbarPosition;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ConnectorHierarchyChangeEvent;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentContainerConnector;
import com.vaadin.shared.Connector;
import com.vaadin.shared.ui.Connect;

@Connect(BootstrapNavbar.class)
public class BootstrapNavbarConnector extends AbstractComponentContainerConnector {

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapNavbar.class);
    }

    @Override
    public BootstrapNavbarState getState() {
        return (BootstrapNavbarState) super.getState();
    }

    @Override
    public VBootstrapNavbar getWidget() {
        return (VBootstrapNavbar) super.getWidget();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapNavbarState state = getState();

        VBootstrapNavbar navBar = getWidget();

        for (Connector connector : state.getNavs()) {
            navBar.add(((ComponentConnector) connector).getWidget());
        }
        navBar.setInverse(state.isInverse());
        navBar.setPosition(NavbarPosition.valueOf(state.getPosition()));
    }

    @Override
    public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) {

    }

    @Override
    public void updateCaption(ComponentConnector connector) {

    }

}